package br.ufrj.dcc.ad.stats;

import br.ufrj.dcc.ad.Simulator;
import br.ufrj.dcc.ad.Util;
import br.ufrj.dcc.ad.event.Event;
import br.ufrj.dcc.ad.event.PackageReceivedByReceiverEvent;

public class VazaoMediaStats extends Statistics {
	
	private Long packages = 0l;
	private int sessionId;
	
	public VazaoMediaStats(int sessionId) {
		this.sessionId = sessionId;
	}
	
	@Override
	protected void doStatistic(Event event) {
		if (!(event instanceof PackageReceivedByReceiverEvent)) return;
		
		PackageReceivedByReceiverEvent e = (PackageReceivedByReceiverEvent) event;
		
		if(e.getPackage().getSessionId().intValue() != sessionId) return;
		
		packages++;
	}

	@Override
	protected void finishStatistic() {
		//nothing to do
	}

	public Double getVazaoMedia() {
		final double seconds = Util.convertMillisToSeconds(Simulator.getTime());
		return packages / ((double)seconds);
	}

}
